package com.mmz.test.datastructure;

public class BineryTree {

	public static void main(String[] args) {
		
		company();
	}
	
	// 公司的一个层级结构
	static void company(){
		Node A = new Node(1, "A");
		Node B = new Node(1, "B");
		Node D = new Node(1, "D");
		Node E = new Node(1, "E");
		Node H = new Node(1, "H");
		Node I = new Node(1, "I");
		A.left=B;
		B.left=D;
		B.right=E;
		D.left=H;
		D.right=I;
		loop(A,"B");
	}
	
	static void loop(Node root,Object value){
		if(root!=null){
			if(root.value.equals(value)){
				printLoop(root,0);
				return;
			}
			else{
				loop(root.left,value);
				loop(root.right,value);
			}
		}
	}
	
	static void printLoop(Node root,int floor){
		if(root!=null){
			System.out.println(_print(floor)+root.value);
			floor++;
			printLoop(root.left,floor);
			printLoop(root.right,floor);
		}
		
	}
	
	static String _print(int floor){
		StringBuffer sb=new StringBuffer("");
		for(int i=0;i<floor;i++){
			sb.append("-");
		}
		return sb.toString();
	}
	
	static class Node{
		int key;
		Object value;
		public Node(int key,Object value){
			this.key = key;
			this.value = value;
		}
		Node left;
		Node right;
	}
	
	

}
